import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  ElementPlusResolver,
  NaiveUiResolver,
} from 'unplugin-vue-components/resolvers'
import vueJsx from '@vitejs/plugin-vue-jsx'
import qiankun from 'vite-plugin-qiankun'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({ resolvers: [ElementPlusResolver(), NaiveUiResolver()] }),
    Components({ resolvers: [ElementPlusResolver(), NaiveUiResolver()] }),
    qiankun('sub-vueComponent', { useDevMode: true }),
  ],
  base: process.env.NODE_ENV === 'development' ? '/' : 'http://115.190.202.175/vueComponent/', // 强制设置
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  resolve: {
    // 路径别名
    alias: [{ find: '@', replacement: path.resolve(__dirname, 'src') }],
  },
  build: {
    outDir: 'dist_vueComponent',
  },
  server: {
    // 热更新
    hmr: true,
    // 打开端口
    port: 7035,
  },
})
